<?php

/**
 * This is the model class for table "products".
 *
 * The followings are the available columns in table 'products':
 * @property integer $id
 * @property string $name
 * @property integer $price
 * @property string $image
 * @property string $thumb
 * @property string $description
 * @property string $short_descript
 * @property integer $promote
 * @property string $created
 * @property string $updated
 * @property integer $category_id
 * @property string $code
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property Categories $category
 * @property Slides[] $slides
 */
class ProductsBase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ProductsBase the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'products';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, price, image, thumb, created, category_id, code', 'required'),
			array('price, promote, category_id, status', 'numerical', 'integerOnly'=>true),
			array('name, image, thumb', 'length', 'max'=>255),
			array('code', 'length', 'max'=>10),
			array('description, short_descript, updated', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, price, image, thumb, description, short_descript, promote, created, updated, category_id, code, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
			'slides' => array(self::HAS_MANY, 'Slides', 'product_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'price' => 'Price',
			'image' => 'Image',
			'thumb' => 'Thumb',
			'description' => 'Description',
			'short_descript' => 'Short Descript',
			'promote' => 'Promote',
			'created' => 'Created',
			'updated' => 'Updated',
			'category_id' => 'Category',
			'code' => 'Code',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('image',$this->image,true);
		$criteria->compare('thumb',$this->thumb,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('short_descript',$this->short_descript,true);
		$criteria->compare('promote',$this->promote);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('updated',$this->updated,true);
		$criteria->compare('category_id',$this->category_id);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}